package com.mentalsurvey.controller;

import com.mentalsurvey.entity.Score;
import com.mentalsurvey.entity.ScoreWithPaperDetails;
import com.mentalsurvey.service.ScoreService;
import com.mentalsurvey.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/score")
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    @PostMapping("/submit")
    public Result<?> submitScore(@RequestBody Score score) {
        int result = scoreService.saveScore(score);
        if (result > 0) {
            return Result.success("保存成功");
        } else {
            return Result.error("保存失败");
        }
    }

    @GetMapping("/details")
    public Result<List<ScoreWithPaperDetails>>  getScoreDetails(@RequestParam("userId") int userId) {
        return  Result.success(scoreService.getScoreWithPaperDetails(userId));
    }
}

